<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    /**
 * @param {number[][]} isConnected
 * @return {number}
 */
    var findCircleNum = function (isConnected) {
      let n = isConnected.length
      let visited = new Array(n).fill(false), province = 0
      var dfs = function (i) {
        for (let j = 0; j < n; j++) {
          if (isConnected[i][j] == 1 && !visited[j]) {
            visited[j] = true
            dfs(j)
          }
        }
      }
      for (let i = 0; i < n; i++) {
        if (!visited[i]) {
          dfs(i)
          province++
        }
      }
      return province
    };
  </script>
</body>

</html>